//
//  YDYStatus.m
//  DY_Weibo3
//
//  Created by 杨德勇 on 2016/8/22.
//  Copyright © 2016年 杨德勇. All rights reserved.
//

#import "YDYStatus.h"
#import <SDWebImageDownloader.h>
#import <SDWebImageManager.h>
@implementation YDYStatus
-(YDYStatus*)initWithDict:(NSDictionary *)dict{
    [self setValuesForKeysWithDictionary:dict];
    return self;
}
+(YDYStatus *)ydyStatusWithDict:(NSDictionary *)dict{
    return [[self alloc]initWithDict:dict];
}
//-(void)setPic_urls:(NSArray *)pic_urls{
//    _pic_urls = pic_urls;
//    
//    if (pic_urls.count == 0) return;
//    
//    for (NSDictionary *dict in pic_urls) {
//        NSString *imgURLString = dict[@"thumbnail_pic"];
//        NSURL *imgurl = [NSURL URLWithString:imgURLString];
//        [[SDWebImageManager sharedManager]downloadImageWithURL:imgurl options:0 progress:^(NSInteger receivedSize, NSInteger expectedSize) {
//            
//        } completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, BOOL finished, NSURL *imageURL) {
//            YDYLog(@"缓存图片完成");
//        }];
//        
//    }
//    //缓存图片
//    
//    
//    
//}

-(void)setValue:(id)value forKey:(NSString *)key{
    if ([key isEqualToString:@"user"]) {
        self.user = [YDYUser ydyUserWithDict:value];
        return;
    }
    
    if ([key isEqualToString:@"id"]) {
        self.idStr = value;
        return;
    }
    [super setValue:value forKey:key];
}
-(void)setValue:(id)value forUndefinedKey:(NSString *)key{
    
}

//-(void)setCreated_at:(NSString *)created_at{
//    
//    NSString *timeText = @"??";
//    NSDateFormatter *formatter = [[NSDateFormatter alloc]init];
//    formatter.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
//    //@"Mon Aug 22 13:36:24 +0800 2016"	0x00006080000595f0
//    formatter.dateFormat = @"EE MM dd HH:mm:ss Z yyyy";
//    NSDate *creatDate = [formatter dateFromString:created_at];
//    NSInteger interval =(int) [[[NSDate alloc]init] timeIntervalSinceDate:creatDate];
//    
//    /**
//     1.应该扩展NSCalendar 类
//     NSCalendar *cal = [NSCalendar currentCalendar];
//     NSDateComponents *com = [cal components:NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay|NSCalendarUnitHour|NSCalendarUnitMinute|NSCalendarUnitSecond fromDate:creatDate];
//     YDYLog(@"%ld,%ld,%ld",com.year,com.minute,com.second);
//     
//     BOOL a = [cal isDateInToday:creatDate];*/
//    
//    //下面的代码可以用
//    if (interval < 60) {
//        timeText = @"刚刚";
//    }else if (interval < 60 * 60){
//        timeText = [NSString stringWithFormat:@"%ld分钟前",interval / 60];
//    }else if (interval < 60 * 60 * 24){
//        timeText = [NSString stringWithFormat:@"%ld小时前",interval / (60 * 60)];
//    }else if (interval < 60 * 60 * 24 * 30){
//        timeText = [NSString stringWithFormat:@"%ld天前",interval / (60 * 60 * 24)];
//    }else{
//        timeText = @"很久之前";
//    }
//    
//    _created_at = timeText;
//    
//
//}
@end
